home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / gnu / fpu881 / src6.zoo / pow.c < prev    next >
C/C++ Source or Header  |  1991-09-24  |  461b  |  39 lines

  1. /*
  2.     computes a^b.
  3.     uses log and exp
  4. */
  5.  
  6. #include    <errno.h>
  7. int errno;
  8. double log(double), exp(double);
  9.  
  10. double
  11. pow(arg1,arg2)
  12. double arg1, arg2;
  13. {
  14.     double temp;
  15.     long l;
  16.  
  17.     if(arg1 <= 0.)
  18.     {
  19.         if(arg1 == 0.)
  20.         {
  21.             if(arg2 <= 0.)
  22.                 goto domain;
  23.             return(0.);
  24.         }
  25.         l = arg2;
  26.         if(l != arg2)
  27.             goto domain;
  28.         temp = exp(arg2 * log(-arg1));
  29.         if(l & 1)
  30.             temp = -temp;
  31.         return(temp);
  32.     }
  33.     return(exp(arg2 * log(arg1)));
  34.  
  35. domain:
  36.     errno = EDOM;
  37.     return(0.);
  38. }
  39.